﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Text;
using Components;

namespace Components
{
    public class LogHelper
    {
        private static LogHelper _entity;

        private static string _logUrl = null;

        //LOG日志的位置
        private static string LOG_PATH
        {
            get
            {
                if (string.IsNullOrEmpty(_logUrl))
                {
                    _logUrl = ConfigurationManager.AppSettings["LogUrl"];

                    if (string.IsNullOrEmpty(_logUrl))
                    {
                        _logUrl = "D:\\log";
                    }
                }

                return _logUrl;
            }
        }

        public static LogHelper Entity
        {
            get
            {
                if (null == _entity)
                {
                    _entity = new LogHelper();
                    Logger.SetLogPath(LOG_PATH); //设置Log的根目录文件
                }
                return _entity;
            }
        }

        /// <summary>
        /// 书写Log
        /// </summary>
        /// <param name="errmsg"></param>
        public void Out(string errmsg)
        {
            Logger.WriteError("", errmsg);
        }



        /// <summary>
        /// 书写Log
        /// </summary>
        /// <param name="e"></param>
        public void Out(Exception e)
        {
            Logger.WriteError(e);
        }

        public void Out(IDbCommand cmd)
        {
            Logger.WriteSqlCommand(cmd);
        }
    }
}
